package com.zeroup.auto.utils;

import android.content.Context;
import android.util.Log;

import com.jaredrummler.android.processes.AndroidProcesses;
import com.jaredrummler.android.processes.models.AndroidAppProcess;



import java.util.List;

public class AppUtils {

    public static boolean isRun(Context context,String packageName){
        boolean isruning = false;
        AndroidAppProcess info = getAppProcessInfo(context,packageName);
        if(info==null){
            return isruning;
        }
        isruning = true;
        return isruning;
    }

    public static AndroidAppProcess getAppProcessInfo(Context context,String packageName){

        AndroidAppProcess appProcessInfo=null;
        List<AndroidAppProcess> processes = AndroidProcesses.getRunningAppProcesses();
        for (AndroidAppProcess info:processes){
            Log.d("name====>" ,info.name);
            if(info.name.equals(packageName)){
                appProcessInfo = info;
                break;
            }
        }
        return appProcessInfo;
    }


    public static boolean isRunKill(Context context,String packageName){
        boolean isruning = false;
        AndroidAppProcess info = getAppProcessInfo(context,packageName);
        Log.d("====>","获取进程名称");
        if(info==null){
            return isruning;
        }
        Log.d("====>",info.name);
        android.os.Process.killProcess(info.pid);
        isruning = true;
        return isruning;
    }
}
